package com.blogspot.radialmind;

import java.util.ArrayList;
import java.util.List;

/**
 * This is an abstract base class for the types of graphs that can be 
 * constructed from sar output. At this time, there are two types.
 * See the comments in the subclasses to find out what they do.
 * 
 * @author gt
 *
 */
public abstract class AbstractGraph implements IGraph {
	
	protected int COLUMN_START_INDEX = 2;
	protected List<String> colNames = new ArrayList<String>();
	private String title;
	
	public AbstractGraph( String title, List<ITerm> columns ) {
		for ( ITerm term: columns ) {
			colNames.add( sanitizeColName( term.toString() ) );
		}
		this.title = title;
	}
	
	/**
	 * How many columns to skip before getting to the data
	 */
	public int skip() {
		return COLUMN_START_INDEX;
	}
	
	public List<String> getColumnNames() {
		return colNames.subList( COLUMN_START_INDEX, colNames.size() );
	}
	
	public int getNumDataCols() {
		return colNames.size() - COLUMN_START_INDEX;
	}
	
	public String getTitle() {
		return title;
	}
	
	public abstract long getStartTimestamp();
	public abstract long getEndTimestamp();
	public abstract String getName();
	
	/**
	 * Remove invalid characters for rrdtool.
	 */
	private String sanitizeColName( String readColName ) {
		readColName = readColName.replace( "%", "pct" );
		readColName = readColName.replace( "/", "_" );
		return readColName;
	}
}
